<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="edu.jhu.secondhome.database.beans.Hotel"%>
<%@page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<title>Second Home Inc. :: Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="search_includes.jsp"%>

</head>
<body>
	<div id="page-wrap" align="center">
		<%@ include file="../navigation.jsp"%>
<%
      if (request.getSession().getAttribute("user") == null)
      {
        out.write("<table>");
      }
        ArrayList<String> errors = (ArrayList<String>) request.getAttribute("errors");
        if (errors != null && errors.size() > 0)
        {
          out.write("<tr><td>");
          out.write("<div align=\"center\">");
          out.write("<table><tr><td>");

          for (String error : errors)
          {
            out.write("<div id=\"error\">" + error + "</div><br />");
          }
          out.write("</td></tr></table>");
          out.write("</div></td></tr></table>");
        }
        %>
        <br />

		<table id="hotels">
			<thead>
				<tr>
					<!-- Thumbnail -->
					<th>Photo</th>
				    <th>Name</th>
					<th>Description</th>
					<th>Amenities</th>
					<th>Address</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${hotels}" var="hotel">
					<%
					  Hotel hotel = (Hotel) pageContext.getAttribute( "hotel" );

					    String addr1 = "";
					    String addr2 = "";
					    String addr3 = "";
					    String city = "";
					    String state = "";
					    String zip = "";
					    if ( hotel != null )
					    {
					      addr1 = hotel.getAddressSubField( "addr1" );
					      addr2 = hotel.getAddressSubField( "addr2" );
					      addr3 = hotel.getAddressSubField( "addr3" );
					      city = hotel.getAddressSubField( "city" );
					      state = hotel.getAddressSubField( "state" );
					      zip = hotel.getAddressSubField( "zip" );
					    }
					%>
					<tr>
						<td>
						  <img src="images/${hotel.thumbnail}" alt="${hotel.hotelName}" style="width:325px;height:230px">
						</td>
						<td><c:out value="${hotel.hotelName}" /></td>
						<td><c:out value="${hotel.description}" /></td>
						<td><c:out value="${hotel.amenities}" /></td>
						<td><%=addr1 + addr2 + addr3 + " " + city + ", " + state + " " + zip%></td>
						<td align="center">
						  <form action="controller" method="post">
				  	    <input type="hidden" name="source" value="viewRoomAvailability"/>
		  			    <input type="hidden" name="hotelName" value="${hotel.hotelName}"/>
		  			    <input type="hidden" name="check-in" value="<%= request.getAttribute( "check-in" ) %>"/>
		  			    <input type="hidden" name="numDays" value="<%= request.getAttribute( "numDays" ) %>"/>
		  			    <input type="hidden" name="numPeople" value="<%= request.getAttribute( "numPeople" ) %>"/>
                <input type="submit" name="reserveRoom" value="View Availability"/>
					    </form>
					  </td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>
</body>
</html>